<template>
    <div id="html">
        <!-- 标题 -->
        <div class="title">
            <h4 v-text='info.title'></h4>
            <!-- 子标题 -->
            <p>{{info.add_time | datefmt('YYYY-MM-DD')}} {{info.click}}次浏览</p>
        </div>
        <!-- 内容区域 -->
        <div id="content" v-html="info.content">
           
        </div>

        <!-- 评论内容 -->
        <comment-box :id='this.id'></comment-box>
    </div>
</template>

<script>
//导入评论子组件
import comment from '../subcomponents/comment.vue'
export default{
    data(){
        return{
            // id: this.$route.params.id, //将url地址传递过来
            id: 0, //将url地址传递过来
            // newsinfo: {} //新闻对象
            info:{},
        }
    },
    created(){
        this.id = this.$route.params.id;
        this.getinfo();
    },
    methods:{
        getinfo(){//获取新闻详情
           var url = 'http://wxtest.centaline.com.cn/api/api?type=getnew&newid='+this.id;

           this.$http.get(url).then(function(res){
               var body = res.body;
               if(body.status !=0){
                alert(body.message);
                return;
               }else{
                   this.info = body.message;
               }
           })
        }
    },
    components:{//注册子组件
        'comment-box': comment
    }
}
</script>

<style lang="scss" scoped>
.title h4{
    color: #0094ff;
}
.title p{
    color:rgba(0,0,0,0.5);
}
.title,#content{
    padding: 5px;
}
</style>

